package com.itqn.servlet;

import com.itqn.pojo.Employee;
import com.itqn.pojo.Member;
import com.itqn.service.EmployeeService;
import com.itqn.service.Impl.EmployeeServiceImpl;
import com.itqn.service.Impl.MemberServiceImpl;
import com.itqn.service.MemberService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(value = "/employeeStatus")
public class EmployeeUpdateStatusServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 解决post提交中文乱码
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html; charset=UTF-8");
        // 获取文本框的值
        String id = request.getParameter("id");
        String status = request.getParameter("status");
        // 创建业务逻辑层对象
        EmployeeService employeeService = new EmployeeServiceImpl();
        try {
            // 创建实体类对象
            // 给实体类对象的属性设置值
            Employee employee = new Employee();
            employee.setId(Long.parseLong(id));
            if (Integer.parseInt(status) == 0) {
                employee.setStatus(0);
            }
            if (Integer.parseInt(status) == 1) {
                employee.setStatus(1);
            }
            employeeService.updatestatic(employee);

        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }
}